Any code that runs asynchronously or as a callback routine and that accesses the calling application's A5 world must ensure that the A5 register correctly points to the boundary between the application parameters and the application global variables. To accomplish this, you can call the SetCurrentA5 function at the beginning of any asynchronous or callback code that isn't executed at interrupt time. If the code is executed at interrupt time, you must use the SetA5 function to set the value of the A5 register. (You determine this value at noninterrupt time by calling SetCurrentA5 .) Then you must restore the A5 register to its previous value before the interrupt code returns.
You can use the SetCurrentA5 function to get the current value of the system global variable CurrentA5 .
FUNCTION SetCurrentA5: LongInt;
The SetCurrentA5 function does two things: First, it gets the current value in the A5 register and returns it to your application. Second, SetCurrentA5 sets register A5 to the value of the low-memory global variable CurrentA5 . This variable points to the boundary between the parameters and global variables of the current application.
You cannot reliably call SetCurrentA5 in code that is executed at interrupt time unless you first guarantee that your application is the current process (for example, by calling the Process Manager function GetCurrentProcess ). In general, you should call SetCurrentA5 at noninterrupt time and then pass the returned value to the interrupt code.
In interrupt code that accesses application global variables, use the SetA5 function first to restore a value previously saved using SetCurrentA5 , and then, at the end of the code, to restore the A5 register to the value it had before the first call to SetA5 .
FUNCTION SetA5 (newA5: LongInt): LongInt;